﻿@using CNKI.TPI.Web.Base
@using CNKI.TPI.Web.Search.Model;
@model IList<SYS_CMS_SUBMIT>
@{
    ViewBag.Title = "论文提交";
}
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/Tookit/kindeditor/kindeditor-min.js")
<style>
    object {
        display: inline;
    }

    .talkDivBg {
        display: none !important;
    }
</style>
<script type="text/javascript">
    var regFlage = true;
    // 下拉框选择项变化的处理事件方法(CurName-当前的字段名，Par-相关联的上级字段集合)
    function SelectedChange(dbcode, CurName, Par) {
        var pareVaue = "";
        var parentColumns = Par.split(",");

        for (var i = 0; i < parentColumns.length; i++) {
            pareVaue += parentColumns[i].toString() + ":" + $("#" + parentColumns[i]).val() + ",";
        }

        pareVaue = pareVaue.substring(0, pareVaue.length - 1);
        $.getJSON("@Html.Raw(Url.Action("GetSubject", "SubmitOnline"))", { dbcode: dbcode, CurName: CurName, pareVaue: pareVaue }, function (data) {
            $("#" + CurName + "").empty(); //清空内容
            $.each(data, function (i, item) {

                $("<option></option>").val(item["Value"]).text(item["Text"]).appendTo($("#" + CurName + ""));

            });
        });
    }

    // 文本域离开时变化的处理
    function TextareaOnblur(objSourceID_hz, objSourceID_py) {

        var hz = $("#" + objSourceID_hz).val();
        $.post("@Html.Raw(Url.Action("GetPinyinByHz", "SubmitOnline"))", { source: hz }, function (data) {
            $("#" + objSourceID_py + "").val(""); //清空内容
            $("#" + objSourceID_py + "").val(data);

        });
    }
    function GetClsNaviName(dbcode, NaviName, NaviValue) {
        messageAlert(dbcode);
        messageAlert(NaviName);
        messageAlert(NaviValue);
    }
    //密级级联保密期限
    function SetSecurity(dbcode) {

        //messageAlert(dbcode);

    }
    function closemodal() {
        $(".talkDivBg").hide();
        $('.message').hide();
    }
    //非空验证
    function blankText(e) {
        var value = $(e).val();
        if ($(e).parent().find(".red").html() == "*" && (value == "" || value == " ")) {
            $(e).parent().find(".message").remove();
            $(e).parent().append(" <span style=\"color:red\" class=\"f-help message\">不允许为空！</span)");
            return false;
        }
        else {
            $(e).parent().find(".message").remove();
            return true;
        }
    }
    //文本框特殊字符
    function onBlurText(e) {
        if (blankText(e)) {
            var value = $(e).val();
            if (!regtext(value)) {
                $(e).parent().find(".message").remove();
                $(e).parent().append(" <span style=\"color:red\" class=\"f-help message\">不允许输入特殊字符！</span)");
                return false;
            }
            else {
                $(e).parent().find(".message").remove();
                return true;
            }
        }

    }
    //邮箱验证
    function onBlurEmail(e) {
        if (blankText(e)) {
            var value = $(e).val();
            if (!regemail(value)) {
                $(e).parent().find(".message").remove();
                $(e).parent().append(" <span style=\"color:red\" class=\"f-help message\">请输入正确的邮箱格式！</span)");
                return false;
            }
            else {
                $(e).parent().find(".message").remove();
                return true;
            }
        }
    }
    //关键词验证
    function onBlurKeyWord(e) {
        if (blankText(e)) {
            var value = $(e).val();
            if (!regKeyWord(value)) {
                $(e).parent().find(".message").remove();
                $(e).parent().append(" <span style=\"color:red\" class=\"f-help message\">不允许输入特殊字符！</span)");
                return false;
            }
            else {
                $(e).parent().find(".message").remove();
                return true;
            }
        }
    }
</script>

<div class="wrap form form-h mh" style="border: 0px">
    <div class="talkDivBg-message message" style="z-index: 999;">
        <div class="talkDiv talkDivTr talkW-550 form-h message" style="margin-top: -278px; display: none">
            <div class="talkDiv-title" style="padding-top: 10px">
                <h3 class='bbsolid'><i class="blue-block"></i><span>检索导航</span></h3>
                <a class="icon icon-close" title="关闭" onclick="closemodal()" href="javascript:void(0);"><i class="iconfont icon-error3"></i></a>
            </div>
            <div class="talkDiv-body talkDiv-body1" id="messageDiv" style="padding: 0px 40px 10px">
            </div>
            <div class="f-gp" style="margin-left: 60px; padding-bottom: 30px; margin-top: 5px">
                <div class="f-ct">
                    <button id="btnSubmit" class="btn btn-m btn-prim-f btn-submit">确定</button>
                    &nbsp;&nbsp
                    <a href="javascript:void(0);" id="btnClose" class="btn btn-m btn-submit btn-defa-f" onclick="closemodal()">取消</a>
                </div>
            </div>
        </div>
    </div>
    <div class="power-login">
        <h2 class="bbsolid bbsolidw2 mb10"><i class="blue-block"></i><span>【@ViewBag.dbName】提交</span></h2>
        <form id="LoginForm">
            @* //构造配置的具体数据列
            //字段值（根据字段类型不同来构造。字段类型：1-文本框、2-下拉框、3-单选框、4-多选框、5-时间框、6-邮箱框、7-导航框、8-关键词、9-参考文献）*@
            @foreach (var item in Model)
            {
                var a = item.DEFAULTVALUE;
                var b = String.IsNullOrEmpty(Request.Form[item.FIELDNAME]) ? "" : Request.Form[item.FIELDNAME].ToString();
                switch (item.FIELDTYPE)
                {
                    case 1: //文本框
                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct">
                        @Html.TextBox(item.FIELDNAME, ViewBag.dtInfo == null ? item.DEFAULTVALUE : ViewBag.dtInfo.Rows[0][item.FIELDNAME].ToString() as string, new { onblur = "onBlurText(this)", id = item.FIELDNAME, @class = "f-text span5 textvalid" })
                        @if (item.ISALLOWNULL == 1)
                        {
                            <span class="f-help red">*</span>
                        }
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>

                </div>
                        break;

                    case 2: //下拉框
                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct">

                        @{
                           var strchang="";
                            List<SubmitDic> dicJson =(List<SubmitDic>)ViewBag.dicModel;
                            List<SubmitDic> itemdic=dicJson.Where(c=>c.parentColumnName.Contains(item.FIELDNAME)).ToList();
                            
                            if(itemdic!=null && itemdic.Count>0)
                            {
                                SubmitDic objsumb =itemdic[0];
                                strchang="SelectedChange('"+ViewBag.dbCode+"','"+objsumb.columnName+"','"+item.FIELDNAME+"')";
                                
                            }
                        }
                        @if (ViewData[item.FIELDNAME] != null)
                        {
                            @Html.DropDownList(item.FIELDNAME, null, new { id = item.FIELDNAME, @class = "f-select span3",onchange=strchang})
                            if (item.ISALLOWNULL == 1)
                            {
                            <span class="f-help red">*</span>
                            }
                        }
                        else
                        {
                            <select id="@item.FIELDNAME" name="@item.FIELDNAME" class="f-select span3" title="@item.FIELDDISPLAYNAME" onchange="@strchang">
                                <option value=""></option>
                            </select>
                            if (item.ISALLOWNULL == 1)
                            {
                            <span class="f-help red">*</span>
                            }
                        }
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>
                </div>
                        break;

                    case 3: //单选框
                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct radiovalid">

                        @if (!String.IsNullOrEmpty(item.DEFAULTVALUE))
                        {
                            string[] ArrRadioVaue = item.DEFAULTVALUE.Split(new char[] { ',', '，' }, StringSplitOptions.None);
                            for (int i = 0; i < ArrRadioVaue.Length; i++)
                            {
                                if (ViewBag.dtInfo == null)
                                {
                            <label class="f-label">
                                @Html.RadioButton(item.FIELDNAME, ArrRadioVaue[i].ToString(), i == 0 ? true : false, new { id = item.FIELDNAME, @class = "f-checkbox" })
                            </label>                            }
                                else
                                {
                            <label class="f-label">
                                @Html.RadioButton(item.FIELDNAME, ArrRadioVaue[i].ToString(), ViewBag.dtInfo.Rows[0][item.FIELDNAME].ToString() == ArrRadioVaue[i].ToString() ? true : false, new { id = item.FIELDNAME, @class = "f-checkbox" })
                            </label>  }
                            <span>@ArrRadioVaue[i].ToString()</span>
                            }

                            if (item.ISALLOWNULL == 1)
                            {
                            <span class="f-help red">*</span>
                            }
                        }
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>
                </div>
                        break;

                    case 4: //复选框
                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct checkvalid">
                        @if (ViewData[item.FIELDNAME] != null)
                        {

                            foreach (SelectListItem m in (List<SelectListItem>)ViewData[item.FIELDNAME])
                            {
                            <label class="f-label">
                                <input class="f-checkbox" type="checkbox" id="@item.FIELDNAME" name="@item.FIELDNAME" value="@m.Value" @(m.Selected ? "checked='checked'" : "") />
                                @m.Text
                            </label>
                            }
                            if (item.ISALLOWNULL == 1)
                            {
                            <span class="f-help red">*</span>
                            }
                        }
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>

                </div>
                        break;

                    case 5: //时间框

                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct">
                        @{
                        string datavalue = ViewBag.dtInfo == null ? System.DateTime.Now.ToString("yyyy-MM-dd") : ViewBag.dtInfo.Rows[0][item.FIELDNAME].ToString();
                        try
                        {
                            DateTime times = Convert.ToDateTime(datavalue);
                            @Html.TextBox(item.FIELDNAME, times.ToString("yyyy-MM-dd"),
                            new { id = item.FIELDNAME, @class = "f-text span3", @readonly = "true", onfocus = "WdatePicker({dateFmt:'yyyy-MM-dd'})" })
                        }
                        catch
                        {
                            @Html.TextBox(item.FIELDNAME, "",
                            new { id = item.FIELDNAME, @class = "f-text span3", @readonly = "true", onfocus = "WdatePicker({dateFmt:'yyyy-MM-dd'})" })
                        }
                        if (item.ISALLOWNULL == 1)
                        {
                            <span class="f-help red">*</span>
                        }
                        }
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>
                </div>
                        break;

                    case 6: //邮箱框

                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct">
                        @Html.TextBox(item.FIELDNAME, ViewBag.dtInfo == null ? item.DEFAULTVALUE : ViewBag.dtInfo.Rows[0][item.FIELDNAME].ToString() as string, new { onblur = "onBlurEmail(this)", id = item.FIELDNAME, @class = "f-text span5 emailvalid" })
                        @if (item.ISALLOWNULL == 1)
                        {
                            <span class="f-help red">*</span>
                        }
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>
                </div>
                        break;

                    case 7: //导航框

                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct">
                        @{  string strNaviText = "", strNaviValue = "";
                            strNaviValue = ViewBag.dtInfo == null ? item.DEFAULTVALUE : ViewBag.dtInfo.Rows[0][item.FIELDNAME].ToString();
                            string dbcode = ViewBag.dbCode;
                            CNKI.TPI.Web.Search.IBLL.INaviService naviService = Autofac.Integration.Mvc.AutofacDependencyResolver.Current.GetService<CNKI.TPI.Web.Search.IBLL.INaviService>();
                            strNaviText = naviService.GetClsNaviName(dbcode, item.FIELDNAME, strNaviValue);
                        
                            @Html.TextBox("display" + item.FIELDNAME, strNaviText, new { id = "display" + item.FIELDNAME, @class = "f-text span5", ReadOnly = "readonly" })
                            @Html.Hidden(item.FIELDNAME, strNaviValue, new { id = item.FIELDNAME, @class = "f-text span5" })
                      
                        }
                        <span class="f-help"><a href="javascript:showModel('@ViewBag.dbID','@ViewBag.dbCode','@ViewBag.sysid','@item.FIELDNAME')">点我选择导航</a></span>
                        @if (item.ISALLOWNULL == 1)
                        {
                            <span class="f-help red">*</span>
                        }
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>
                </div>

                        break;

                    case 8: //关键词
                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct">
                        @Html.TextBox(item.FIELDNAME, ViewBag.dtInfo == null ? item.DEFAULTVALUE : ViewBag.dtInfo.Rows[0][item.FIELDNAME].ToString() as string, new { onblur = "onBlurKeyWord(this)", id = item.FIELDNAME, @class = "f-text span5 keywordvalid" })
                        @if (item.ISALLOWNULL == 1)
                        {
                            <span class="f-help red">*</span>
                        }
@*      <span class="f-help"><a href="javascript:showModel('@ViewBag.dbID','@ViewBag.dbCode','@ViewBag.sysid','@item.FIELDNAME','/AddKey','@item.FIELDDISPLAYNAME')">配置关键词</a></span>*@
                        <span class="f-help">(如要手动输入请以英文状态下分号 ; 分隔)</span>
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>
                </div>

                        break;

                    case 10: //全文

                <div class="f-gp">
                    <div class="f-lb">
                        <label class="f-label">@(String.IsNullOrEmpty(item.FIELDDISPLAYNAME) ? item.FIELDNAME : item.FIELDDISPLAYNAME):</label>
                    </div>
                    <div class="f-ct">
                        @Html.TextArea(item.FIELDNAME, ViewBag.dtInfo == null ? item.DEFAULTVALUE : ViewBag.dtInfo.Rows[0][item.FIELDNAME].ToString() as string,
                new { id = item.FIELDNAME, @class = "f-textarea span6 fcontent", rows = 6 })
                        @if (item.ISALLOWNULL == 1)
                        {
                            <span class="f-help red">*</span>
                        }
                        <span class="f-help">@item.DESCRIPT</span>
                    </div>
                </div>

                        break;

                }
            }


            @*//密级*@
            <div class="f-gp" style="display: none">
                <div class="f-lb">
                    <label class="f-label">密级:</label>
                </div>
                <div class="f-ct">
                    @if (ViewData["密级"] != null)
                    {
                        @Html.DropDownList("密级", null, new { id = "密级", @class = "f-select span3" })
                    }
                    else
                    {
                        <select id="密级" name="密级" class="f-select span3 "></select>
                    }
                </div>
                <div class="col-md-4">
                    <span style="float: left;">@ViewBag.Security</span>
                </div>
            </div>
            @if (ViewBag.FileInfo != null)
            {
                <div class="f-gp">

                    <div class="f-lb">
                        <label class="f-label">附件列表:</label>
                    </div>
                    <div class="f-ct">
                        @foreach (var Fileitem in ViewBag.FileInfo)
                        {
                            <span id="file_@Fileitem.SYSID" style="margin:8px;display:block">@Fileitem.FILENAME
                                <a href="javascript:void(0)" style="color: #107BCE;" onclick="FileSpanDelete('@Fileitem.FILENAME',@Fileitem.SYSID)">删除</a><br>
                            </span>
                        }

                    </div>
                </div>
            }
            <br />
            @*//上传附件*@

            <div class="f-gp">
                <div class="f-lb">
                    <label class="f-label">上传附件:</label>
                </div>
                <div class="f-ct">
                    @*@Html.TextBox("Files", " ", new { @class = "f-text span3", ReadOnly = "readonly" })*@
                    <span id="spanButtonPlaceHolder" class="btn btn-m inline-block">上传</span>
                    <span class="f-help" style="vertical-align: top">@ViewBag.FileComment</span>
                </div>
            </div>
            <div class="f-gp">
                <div>
                    <div id="divprogresscontainer"></div>
                    <div id="divprogressGroup"></div>
                    @Html.Hidden("FileName", null, new { id = "FileName" })
                    @Html.Hidden("FilePath", null, new { id = "FilePath" })
                    @Html.Hidden("FileLength", null, new { id = "FileLength" })
                    @Html.Hidden("FileFormart", null, new { id = "FileFormart" })
                </div>
            </div>

            <div class="tc">
                <div>
                    <button type="button" id="btnSave" class="btn btn-l btn-submit btn-warn-f" onclick="saveInfo()">保存</button>
                    <input type="reset" style="display: none;" />
                </div>
            </div>

            <input type="hidden" id="dbID" name="dbID" value="@ViewBag.dbID" />
            <input type="hidden" id="dbCode" name="dbCode" value="@ViewBag.dbCode" />
            <input type="hidden" id="dbName" name="dbName" value="@ViewBag.dbName" />
            <input type="hidden" id="sysid" name="sysid" value="@ViewBag.sysid" />
            <input type="hidden" id="info" name="info" value="@ViewBag.info" />
            <input type="hidden" id="ReturnUrl" name="ReturnUrl" value="@ViewBag.ReturnUrl" />
            <input type="hidden" id="digitfilename" name="digitfilename" value="@ViewBag.digitfilename" />

            <input type="hidden" id="FileNum" name="FileNum" value="@ViewBag.FileNum" />
            <input type="hidden" id="FileType" name="FileType" value="@ViewBag.FileType" />
            <input type="hidden" id="FileComment" name="FileComment" value="@ViewBag.FileComment" />
            <input type="hidden" id="FileCount" name="FileCount" value="@ViewBag.FileCount" />
            <input type="hidden" id="Path" name="Path" value="@ViewBag.Path" />
            <input type="hidden" id="DTFlag" name="DTFlag" value="@ViewBag.DTFlag" />
            <input type="hidden" id="FileNameType" name="FileNameType" value="@ViewBag.FileNameType" />
            <input type="hidden" id="FileFieldName" name="FileFieldName" value="@ViewBag.FileFieldName" />
            <input type="hidden" id="SpanFileName" name="SpanFileName" value="" />
            <input type="hidden" id="SpanFileSysid" name="SpanFileSysid" value="" />
        </form>
    </div>
</div>


<!-- Modal局部试图 -->
@*@Html.Partial("_LySwfUpload")*@

@Styles.Render("~/Tookit/Swfupload/css.css")
@Scripts.Render("~/Tookit/Swfupload/swfupload/swfupload.js")
@Scripts.Render("~/Tookit/Swfupload/js/swfupload.queue.js")
@Scripts.Render("~/Tookit/Swfupload/js/fileprogress.js")
@Scripts.Render("~/Tookit/Swfupload/js/filegroupprogress.js")
@Scripts.Render("~/Tookit/Swfupload/js/handlers.js")


@Html.Partial("_KindEditor")
<script type="text/javascript">

    //弹出模式窗体--关键词和导航框
    function showModel(dbid, dbcode, sysid, fieldname) {
        var fieldvalue = $("#" + fieldname).val();
        //判断词字段是否是导航字段
        $.ajax({
            type: "GET",
            url: timestamp("@Html.Raw(Url.Action("GetNavi", "SubmitOnline"))"),
            data: { "DbCode": dbcode, "ClsFieldName": fieldname },
            success: function (msg) {
                if (msg == "True") {
                    $("#messageDiv").load(timestamp("@Html.Raw(Url.Action("Index", "AddNavi"))"), {
                        "dbID": dbid, "dbCode": dbcode, "sysid": sysid, "fieldname": fieldname, "fieldvalue": fieldvalue
                    }, function (result) {
                        $('.talkDivBg').show();
                        $('.message').show();

                    })
                    //var datastr = { "dbID": dbid, "dbCode": dbcode, "sysid": sysid, "fieldname": fieldname, "fieldvalue": fieldvalue };
                    //loadmessage(datastr);
                }
                else {
                    messageAlert(fieldname + "字段不是导航字段，请重新设置！");
                    return false;
                }
            },
            error: function (e) {
                messageAlert(fieldname + "字段不是导航字段，请重新设置！");
                return false;
            }
        })
    }
    function loadmessage(strurl, datastr) {
        $.ajax({
            type: "GET",
            url: timestamp("@Html.Raw(Url.Action("Index", "AddNavi"))"),
            data: datastr,
            success: function (msg) {
                $("#messageDiv").html(msg);
                $('.talkDivBg').show();
                $('.message').show();
            },
            error: function (e)
            { }
        })
    }


    //上传附件
    var swfu;
    var flindex = 0;

    function LoadSwf() {

        swfu = new SWFUpload({
            upload_url: "@Html.Raw(Url.Action("FileUpload", "SubmitOnline"))",
            flash_url: "./Tookit/Swfupload/swfupload/swfupload.swf",
            button_image_url: "./Tookit/Swfupload/images/TestImageNoText_65x29.png",
            use_query_string: true,//这块必须设置，要不然在后台处理的时候是没法获得name的值的
            // File Upload Settings
            file_upload_limit: $("#FileNum").val(), //指定最多能上传多少个文件：0-表示个数无限制
            file_queue_limit: 50, //指定文件上传队列里最多能同时存放多少个文件（当file_upload_limit的数值或者剩余的能上传的文件数量小于file_queue_limit时，则取那个更小的值）
            file_types: $("#FileType").val(), //允许上传的文件类型，当有多个类型时使用分号隔开，比如："*.pdf;*.doc" ,允许所有类型时请使用 "*.*"
            file_types_description: $("#FileComment").val(), //指定在文件选取窗口中显示的文件类型描述
            file_size_limit: "200MB", //指定要上传的文件的最大体积，可以带单位，合法的单位有:B、KB、MB、GB，如果省略了单位，则默认为KB。该属性为0时，表示不限制文件的大小
            button_cursor: SWFUpload.CURSOR.HAND,
            // button_text_style: ".redText { color: #FF0000; }",

            upload_success_handler: function (file, data) {
                ;
                // 过滤文件名
                var json = $.parseJSON(data)
                var bl = true;
                var files = $("#digitfilename").val();
                if (json.r == "True") {
                    messageAlert(json.m);
                    $("#SWFUpload_0_" + file.index).remove(); //删除DIV
                    return false;
                }
                //保存文件名
                if (bl) {
                    //var json = $.parseJSON(data)
                    var progress = new FileProgress(file, swfu.settings.custom_settings.progressTarget);
                    progress.setComplete(this.settings);
                    fg_uploads += file.size;

                    //添加上传时附件删除事件
                    $("#Del_SWFUpload_0_" + file.index).click(function () {
                        ;
                        var filepath = $("#Path").val();
                        var dbcode = $("#dbCode").val();
                        var sysid = $("#sysid").val();
                        var files = $("#digitfilename").val();
                        var filename = json.FileName;
                        $.ajax({
                            type: "POST",
                            url: "@Html.Raw(Url.Action("FileDelete", "SubmitOnline"))",
                            data: { "dbcode": dbcode, "filepath": filepath, "filename": filename, "digitfilename": files, "sysid": sysid },
                            success: function (msg) {
                                var obj = eval(msg);
                                if (obj[0].result == "False") {
                                    messageAlert("操作失败");
                                }
                                else {
                                    $("#SWFUpload_0_" + file.index).remove(); //删除DIV
                                    var stats = swfu.getStats();
                                    stats.successful_uploads--;
                                    swfu.setStats(stats);
                                    //过滤文件名
                                    var files = obj[0].result;
                                    var m = 0;
                                    if (files != "") {
                                        //if (files.indexOf("|") > 0) {   //当只有一个文件时不需要此判断，lp注释
                                        var temp = "";
                                        var arrayName = files.split('|');
                                        for (var i = 0; i < arrayName.length; i++) {
                                            if (filename != arrayName[i]) {
                                                temp += arrayName[i] + "|";

                                            }
                                            else {
                                                m = i;
                                            }
                                        }
                                        temp = temp.substring(0, temp.length - 1);
                                        $("#FileName").val(temp);
                                        $("#digitfilename").val(temp);


                                        $("#FilePath").val(removestr($("#FilePath").val(), m));
                                        $("#FileLength").val(removestr($("#FileLength").val(), m));
                                        $("#FileFormart").val(removestr($("#FileFormart").val(), m));
                                        //}
                                        //else {
                                        //    $("#FileName").val("");//清空
                                        //    $("#digitfilename").val("");//清空
                                        //}
                                    }
                                    else {
                                        $("#FileName").val("");//清空
                                        $("#digitfilename").val("");//清空
                                    }
                                }
                            }
                        })
                    })

                    //修改上传附件的名称********
                    $("div[id*=SWFUpload_0_]").each(function () {
                        if (file.index == $(this).attr("ID").replace("SWFUpload_0_", "")) {
                            $(this).find(".fle").text(json.FileName);
                        }
                    })


                    flindex++;

                    //保存文件名
                    if (files == "") {
                        $("#digitfilename").val(json.FileName);
                    }
                    else {
                        $("#digitfilename").val(files + "|" + json.FileName);
                    }

                    if (flindex > 1) {
                        // $("#FileName").val($("#FileName").val() + "|" + file.name.split('.')[0]);
                        $("#FileName").val($("#FileName").val() + "|" + json.FileName);
                        $("#FilePath").val($("#FilePath").val() + "|" + json.FilePath);
                        $("#FileLength").val($("#FileLength").val() + "|" + json.FileSize);
                        $("#FileFormart").val($("#FileFormart").val() + "|" + json.ExtraName);
                    }
                    else {
                        //  $("#FileName").val(file.name.split('.')[0]);
                        $("#FileName").val(json.FileName);
                        $("#FilePath").val(json.FilePath);
                        $("#FileLength").val(json.FileSize);
                        $("#FileFormart").val(json.ExtraName);
                    }
                }
            }
        });
    }

    function removestr(str, m) {
        var arraystr = str.split('|');
        var temp = "";
        for (var i = 0; i < arraystr.length; i++) {
            if (i == m) {
                continue;
            }
            temp += arraystr[i] + "|";
        }
        temp = temp.substring(0, temp.length - 1);
        return temp;
    }

    //删除附件列表的显示
    function FileSpanDelete(filename, filesysid) {
        ;
        $("#file_" + filesysid).remove(); //删除SPAN
        var stats = swfu.getStats();
        stats.successful_uploads--;
        swfu.setStats(stats);
        //过滤文件名
        var files = $("#digitfilename").val();
        if (files != "") {
            if (files.indexOf("|") > 0) {
                var temp = "";
                var arrayName = files.split('|');
                for (var i = 0; i < arrayName.length; i++) {
                    if (filename != arrayName[i]) {
                        temp += arrayName[i] + "|";
                    }
                }
                temp = temp.substring(0, temp.length - 1);
                $("#digitfilename").val(temp);
            }
            else {
                $("#digitfilename").val("");//清空
            }
        }
        //文件名
        var SpanFileName = $("#SpanFileName").val();
        if (SpanFileName.length > 0) {
            SpanFileName += ",";
        }
        SpanFileName += filename;
        $("#SpanFileName").val(SpanFileName);
        //文件名ID
        var SpanFileSysid = $("#SpanFileSysid").val();
        if (SpanFileSysid.length > 0) {
            SpanFileSysid += ",";
        }
        SpanFileSysid += filesysid;
        $("#SpanFileSysid").val(SpanFileSysid);


    }

    //真正删除附件和记录
    function FileDelete(filename, filesysid) {
        ;
        var filepath = $("#Path").val();
        var dbcode = $("#dbCode").val();
        var sysid = $("#sysid").val();
        var digitfilename = $("#digitfilename").val();
        var filename = filename;
        $.ajax({
            type: "POST",
            url: "@Html.Raw(Url.Action("FileDelete", "SubmitOnline"))",
            data: { "dbcode": dbcode, "filepath": filepath, "filename": filename, "digitfilename": digitfilename, "sysid": sysid },
            success: function (msg) {
                if (msg == "False") {
                    messageAlert("操作失败");
                }
                else {
                    $("#digitfilename").val(msg); //重新赋值
                }
            }
        })
    }


    /** 文件开始上传时触发 **/
    function uploadStart() {

        //数字对象命名获取字段值，不可以为空
        if ($("#FileNameType").val() == 2) {
            if ($("#FileFieldName").val() == "") {
                messageAlert("请在后台管理中设置附件名的字段!");
                return false;
            }
            else {
                var bl = false;
                var arrayNames = $("#FileFieldName").val().split(',');
                for (var i = 0; i < arrayNames.length; i++) {

                    if ($("#" + arrayNames[i]).val() == "") {
                        messageAlert(arrayNames[i] + "不可以为空！");
                        bl = true;
                        break;
                    }
                }
                if (bl) {
                    return false;
                }
                else {
                    //重写上传附件控件的url
                    var filepath = $("#Path").val();
                    var filetype = $("#FileNameType").val();
                    var filefieldname = $("#FileFieldName").val();
                    var dtflag = $("#DTFlag").val();
                    var sysid = $("#sysid").val();
                    var dbcode = $("#dbCode").val();
                    var filefieldvalue = "";
                    var digitfilename = $("#digitfilename").val();
                    var arrayNames = filefieldname.split(',');
                    for (var i = 0; i < arrayNames.length; i++) {

                        if (filefieldvalue.length > 0) {
                            filefieldvalue += ",";
                        }
                        filefieldvalue += $("#" + arrayNames[i]).val();
                    }
                    swfu.setUploadURL("@Html.Raw(Url.Action("FileUpload", "SubmitOnline"))?fPath=" + escape(filepath) + "&fType=" + escape(filetype) + "&fFielValue=" + escape(filefieldvalue) + "&dtFlag=" + dtflag + "&fName=" + escape(digitfilename) + "&sysid=" + escape(sysid) + "&dbcode=" + escape(dbcode));
                }
            }
        }
        else {
            var filepath = $("#Path").val();
            var filetype = $("#FileNameType").val();
            var filefieldname = "";
            var dtflag = "";
            var sysid = $("#sysid").val();
            var dbcode = $("#dbCode").val();
            var filefieldvalue = "";
            var digitfilename = $("#digitfilename").val();
            swfu.setUploadURL("@Html.Raw(Url.Action("FileUpload", "SubmitOnline"))?fPath=" + escape(filepath) + "&fType=" + escape(filetype) + "&fFielValue=" + escape(filefieldvalue) + "&dtFlag=" + dtflag + "&fName=" + escape(digitfilename) + "&sysid=" + escape(sysid) + "&dbcode=" + escape(dbcode));
        }
    }

    /* * 文件加入上传队列失败时触发,触发原因包括:
     * 文件大小超出限制 
     * 文件类型不符合
     * 上传队列数量限制超出等 
     * param file 当前文件 
     * param errorCode 错误代码(参考SWFUpload.QUEUE_ERROR常量) 
     * param message 错误信息 */
    function fileQueueError(file, errorCode, message) {

        if (errorCode == SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED) {
            messageAlert("上传文件队列中超过最大允许上传数.\n" + (message == 0 ? "You have reached the upload limit." : "你只能选择" + (message > 1 ? "不超过" + message + "个文件." : "一个文件.")));
            return;
        }
        switch (errorCode) {
            case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                messageAlert("文件大小超过限制!");
                break;
            case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                messageAlert("不允许上传不符合类型的文件!");
                break;
            case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                messageAlert("不能上传0节字空文件!");
                break;
            default:
                messageAlert("未知错误!");
                break;
        }
    }

    //初始化加载事件
    $(function () {
        //上传附件加载
        LoadSwf();
        // $("#密级").attr("onchange", "SetSecurity('@(ViewBag.dbCode)')");

        //获得Json对象----下拉框级联添加onchange事件
       @* var dicJson = eval('@(Html.Raw(ViewBag.dicJson))');
        for (var i = 0; i < dicJson.length; i++) {
            var cur = dicJson[i].columnName; //当前的字段名
            var par = dicJson[i].parentColumnName;//相关联的上级字段集合
            if (par.length == 0) {
                continue;
            }
            //判断添加onchange事件

            for (var j = 0; j < par.length; j++) {

                if ($("#" + par[j]).attr("onchange") == undefined) {
                    //添加事件
                    $("#" + par[j]).change(function () {
                        SelectedChange('@ViewBag.dbCode', cur, par.toString());
                    });
                }
            }

        }*@

        ////页面提交合法化
        //$('#LoginForm').validation();

    })

    function disablebutton() {
        $("#btnSave").attr("disabled", "disabled");
    }
    function enablebutton() {
        $("#btnSave").removeAttr("disabled", "disabled");
    }
    function saveInfo() {
        var bl = true;
        disablebutton();
        //所有文本框验证非空  遍历所有元素
        $(".f-ct input").each(function () {
            if (!blankText(this)) {
                bl = false;
            }
        })
        //单选框非空验证
        $(".radiovalid").each(function () {
            if ($(this).find(".red").html() == "*") {
                if ($(this).find('input[type=radio]:checked').val() == null) {
                    $(this).find(".message").remove();
                    $(this).append(" <span style=\"color:red\" class=\"f-help message\">不允许为空，请选择！</span)");
                    bl = false;
                }
                else {
                    $(this).find(".message").remove();
                }
            }
        })
        //复选框非空验证
        $(".checkvalid").each(function () {
            if ($(this).find(".red").html() == "*") {
                if ($(this).find("input:checked").size() <= 0) {
                    $(this).find(".message").remove();
                    $(this).append(" <span style=\"color:red\" class=\"f-help message\">不允许为空，请选择！</span)");
                    bl = false;
                }
                else {
                    $(this).find(".message").remove();
                }
            }
        })


        //全文框验证
        $(".fcontent").each(function () {
            if (!blankText(this)) {
                bl = false;
            }

        })

        //验证文本框特殊字符
        $(".textvalid").each(function () {
            if (!onBlurText(this)) {
                bl = false;
            }
        })
        //验证邮箱格式
        $(".emailvalid").each(function () {
            if (!onBlurEmail(this)) {
                bl = false;
            }
        })
        //验证关键词特殊字符
        $(".keywordvalid").each(function () {
            if (!onBlurKeyWord(this)) {
                bl = false;
            }
        })
        ;
        if (bl) {
            var urlstr = "@Html.Raw(Url.Action("SubmitSave", "SubmitOnLine"))";
            $.ajax({
                type: "POST",
                url: urlstr,
                data: $('#LoginForm').serialize(),
                async: false,
                error: function (request) {
                    messageAlert("操作失败！");
                    enablebutton();
                },
                success: function (data) {
                    var sysid = $("#sysid").val()
                    if (sysid == "-1" || sysid == "") {
                        messageAlert(data.m);
                        if (data.r == "True") {
                            $("input[type=reset]").trigger("click");//清空表单的值
                            $(".progressobj").html("");
                        }
                    }
                    else {
                        ////处理删除附件问题
                        //var SpanFileName = $("#SpanFileName").val();
                        //var SpanFileSysid = $("#SpanFileSysid").val();
                        //if (SpanFileName != "") {
                        //    if (SpanFileName.indexOf(",") > 0) {
                        //        var arrayName = SpanFileName.split(',');
                        //        var arraySysid = SpanFileSysid.split(',');
                        //        for (var i = 0; i < arrayName.length; i++) {
                        //            FileDelete(arrayName[i], arraySysid[i]);
                        //        }
                        //    }
                        //    else {
                        //        FileDelete(SpanFileName, SpanFileSysid);
                        //    }
                        //}
                        $("#SpanFileName").val(""); //清空
                        $("#SpanFileSysid").val(""); //清空
                        $("#digitfilename").val(data.f); //重新赋值
                        confirmDialogSure(data.m, function () {
                            window.opener.search()//因为修改时新插入一条数据，删除了原有数据，所以需要刷新父窗体
                            window.close();//修改时，保存后关闭当前页
                        })

                    }
                    enablebutton();
                }
            });
        }
        else {
            messageAlert("请检查各项输入是否符合规则！");
            enablebutton();
            return;
        }
    }
</script>

